#include<iostream>

using namespace std;

int ncases;
unsigned long int n;

unsigned long int invert(unsigned long int nn)
{
    unsigned long int invertedNumber = 0;
    int numbers[100]={0};
    int i=0; 
    int unit = 1;
    
    while(nn>0) {
        numbers[i++] = (nn%10);
        nn /= 10; 
    }
    for(int j=i-1; j>=0; j--) {
        invertedNumber += numbers[j]*unit;
        unit *=10;
    }
    return invertedNumber;
}


bool isCapicua(unsigned long int  nn)
{
    return (invert(nn) == nn);
}

void solve() {
    int counter = 0;
    while(!isCapicua(n)) {
        n += invert(n);
        counter++;
    }
    cout << counter << " " << n << endl;
}

void read() {
   cin >> ncases;
   for(int i=0; i<ncases; i++) {
      cin >> n;
      solve();
   }
}

int main() {
   read();
   return 0;
}
